﻿using System;
using KKCai.TC.App.Model;
using KKCai.TC.App.Core;
using NHibernate.Criterion;
using System.Collections.Generic;

namespace KKCai.TC.App.DAL
{
    internal class RecordDao
    {
        public RecordInfo Get(string phase)
        {
            return SessionManager.Instance.GetSession()
                .CreateQuery("from RecordInfo r where r.Phase = ?")
                .SetString(0, phase)
                .UniqueResult<RecordInfo>();
        }

        public void Save(RecordInfo info)
        {
            SessionManager.Instance.GetSession().Save(info);
        }

        public IList<RecordInfo> Order(string propertyName, bool ascending, int limit)
        {
            return SessionManager.Instance.GetSession()
                .CreateCriteria(typeof(RecordInfo))
                .AddOrder(new Order(propertyName, ascending))
                .SetMaxResults(limit)
                .List<RecordInfo>();
        }
    }
}
